home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS02.ADF
/
IFF
/
saveilbm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-30
|
6KB
|
209 lines
/***************************************************************************
* SaveILBM.c -- Save raw raster image as ILBM file
* by Carolyn Scheppner CBM 01/86
* Using IFF rtns by J.Morrison and S.Shaw of Electronic Arts
*
* Linkage information:
* FROM LStartup.obj, SaveILBM.o, iffw.o, ilbmw.o, packer.o
* TO SaveILBM
* LIBRARY LC.lib, Amiga.lib
***************************************************************************/
#include <exec/types.h>
#include <exec/memory.h>
#include <libraries/dos.h>
#include <graphics/gfxbase.h>
#include <graphics/rastport.h>
#include <graphics/gfx.h>
#include <graphics/view.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/dos.h>
#include <iff/ilbm.h>
#define bufSize 512
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
ULONG DosBase;
struct Window *activeWindow;
struct Screen *activeScreen;
struct Screen *firstScreen;
struct Screen *nextScreen, *highScreen;
struct View *thisView;
struct View *picView = 0;
struct ViewPort *picViewPort;
struct BitMap *picBitMap;
WORD *picColorTable;
/* main() */
void main(argc,argv)
int argc;
char **argv;
{
LONG file;
IFFP iffp = NO_FILE;
char ch[2];
BPTR CliInput;
SHORT topEdge;
int i;
if (argc < 2)
printf("Usage: 'SaveILBM filename'\n\n");
else
{
if ((IntuitionBase =
(struct IntuitionBase *)OpenLibrary("intuition.library",0))==NULL)
cleanexit(-1);
if ((GfxBase =
(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL)
cleanexit(-1);
if ((DosBase = OpenLibrary("dos.library",0))==NULL )
cleanexit(-1);
printf("\nMove screens so screen to save is highest.\n");
printf("Then click here and respond to prompt:\n\n");
printf(" Save highest screen <y or n> ? ");
CliInput = Input();
Read(CliInput,&ch[0],2);
if((ch[0]=='y') || (ch[0]=='Y'))
{
file = Open(argv[1], MODE_NEWFILE);
if(file)
{
Write(file,"x",1); /* so Seek to beginning works ? */
Forbid();
firstScreen = IntuitionBase->FirstScreen;
topEdge = 400;
nextScreen = highScreen = firstScreen;
while( nextScreen != NULL )
{
if(nextScreen->TopEdge < topEdge)
{
topEdge = nextScreen->TopEdge;
highScreen = nextScreen;
}
nextScreen = nextScreen->NextScreen;
}
Permit();
picViewPort = &( highScreen->ViewPort );
printf("\nWill save selected screen in 5 seconds.\n");
for(i=0;i<5*60;i++) WaitTOF();
printf("\nSaving highest screen as '%s'...\n", argv[1]);
picBitMap = (struct BitMap*)picViewPort->RasInfo->BitMap;
picColorTable = (WORD *)picViewPort->ColorMap->ColorTable;
iffp = PutPicture(file, picBitMap, picColorTable);
Close(file);
}
}
cleanup();
}
}
cleanexit(error)
int error;
{
cleanup();
exit(error);
}
cleanup()
{
if (DosBase) CloseLibrary(DosBase);
if (GfxBase) CloseLibrary(GfxBase);
if (IntuitionBase) CloseLibrary(IntuitionBase);
}
/** PutPicture() ***********************************************************
*
* Put a picture into an IFF file.
* This procedure calls PutAnILBM, passing in an <x, y> location of <0, 0>,
* a NULL mask, and a locally-allocated buffer. It also assumes you want to
* write out all the bitplanes in the BitMap.
*
***************************************************************************/
Point2D nullPoint = {0, 0};
IFFP PutPicture(file, bitmap, colorMap)
LONG file; struct BitMap *bitmap; WORD *colorMap;
{
BYTE buffer[bufSize];
return( PutAnILBM(file, bitmap, NULL,
colorMap, bitmap->Depth, &nullPoint,
buffer, bufSize) );
}
/** PutAnILBM() ************************************************************
*
* Write an entire BitMap as a FORM ILBM in an IFF file.
* This version works for any display mode (C. Scheppner).
*
* Normal return result is IFF_OKAY.
*
* The utility program IFFCheck would print the following outline of the
* resulting file:
*
* FORM ILBM
* BMHD
* CMAP
* BODY (compressed)
*
***************************************************************************/
#define CkErr(expression) {if (ifferr == IFF_OKAY) ifferr = (expression);}
IFFP PutAnILBM(file, bitmap, mask, colorMap, depth, xy, buffer, bufsize)
LONG file; struct BitMap *bitmap; BYTE *mask; WORD *colorMap;
UBYTE depth; Point2D *xy;
BYTE *buffer; LONG bufsize;
{
BitMapHeader bmHdr;
GroupContext fileContext, formContext;
IFFP ifferr;
WORD pageWidth, pageHeight;
pageWidth = (bitmap->BytesPerRow) << 3;
pageHeight = bitmap->Rows;
ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
cmpByteRun1, 0, pageWidth, pageHeight);
/* You could write an uncompressed image by passing cmpNone instead
* of cmpByteRun1 to InitBMHdr. */
bmHdr.nPlanes = depth; /* This must be <= bitmap->Depth */
if (mask != NULL) bmHdr.masking = mskHasMask;
bmHdr.x = xy->x; bmHdr.y = xy->y;
CkErr( OpenWIFF(file, &fileContext, szNotYetKnown) );
CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
CkErr( PutBMHD(&formContext, &bmHdr) );
CkErr( PutCMAP(&formContext, colorMap, depth) );
CkErr( PutBODY(&formContext, bitmap, mask, &bmHdr, buffer, bufsize) );
CkErr( EndWGroup(&formContext) );
CkErr( CloseWGroup(&fileContext) );
return( ifferr );
}